from django import template
register = template.Library()

# Import Notification model with error handling
try:
    from core.models.notification import Notification
except ImportError:
    from core.models import Notification



@register.simple_tag(takes_context=True)
def unread_notifications_count(context):
    user = context.get('request').user
    if user.is_authenticated:
        return Notification.objects.filter(receiver=user, is_read=False).count()
    return ''

@register.filter
def has_any_role(user, role_names):
    """Check if user has any of the specified roles"""
    if not user.is_authenticated:
        return False
    roles = role_names.split(',')
    return user.role_assignments.filter(role__name__in=roles).exists()